//
//  ProtocolDemo.swift
//  Swift3.0_Study
//
//  Created by chengfeng on 2016/10/14.
//  Copyright © 2016年 zhaochengfeng. All rights reserved.
//

import Cocoa

protocol ExampleProtocol {
    var simpleDesc: String { get }
    mutating func change()
}

struct MyPoint: Hashable, Comparable {
    
    var x: Int
    var y: Int
    var hashValue: Int {
        get {
            return x.hashValue + y.hashValue
        }
    }
    
    static func ==(lhs: MyPoint, rhs: MyPoint) -> Bool {
        print("l = \(lhs.hashValue), r = \(rhs.hashValue)")
        return lhs.hashValue == rhs.hashValue
    }
    
    static func <(lhs: MyPoint, rhs: MyPoint) -> Bool {
        return lhs.hashValue < rhs.hashValue
    }
    static func <=(lhs: MyPoint, rhs: MyPoint) -> Bool {
        return lhs.hashValue <= rhs.hashValue
    }
    static func >(lhs: MyPoint, rhs: MyPoint) -> Bool {
        return lhs.hashValue > rhs.hashValue
    }
    static func >=(lhs: MyPoint, rhs: MyPoint) -> Bool {
        return lhs.hashValue >= rhs.hashValue
    }
}




class ProtocolDemo: NSObject, ExampleProtocol {
    var simpleDesc: String = "simple des"
    
    func change() {
        simpleDesc = "new simple description"
        print("changed \(simpleDesc)")
    }
    
    func start() -> Void {
        self .change()
        var struct1 = SimpleStruct()
        struct1.change()
        
        
        let point1 = MyPoint(x: 10, y: 20)
        let point2 = MyPoint(x: 10, y: 21)
        
        print(point1 >= point2)
    }
    
    
    struct SimpleStruct: ExampleProtocol {
        var simpleDesc: String = "simple description"
        mutating func change() {
            self.simpleDesc = "changed simple description"
            print(simpleDesc)
        }
    }
}
